﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using Moq;
using Smalt.Data.Infrastructure;
using Smalt.DomainModels.Models;
using Smalt.Services;

namespace Smalt.Tests.Services
{
    [TestClass]
    public class TeamsServiceTest
    {
        private Mock<IUnitOfWork> unitOfWork;

        [TestInitialize]
        public void InitializeTest()
        {
            unitOfWork = new Mock<IUnitOfWork>();
        }

        [TestMethod]
        public void GetAllItemsTest()
        {
            // Arrange
            IEnumerable<Team> teams = new List<Team>()
            {
                new Team { Name = "Team1"},
                new Team { Name = "Team2"}
            };

            unitOfWork.Setup(uow =>
                uow.Teams.All()).Returns(teams.AsQueryable());

            var service = new TeamsService(unitOfWork.Object);

            // Act
            int teamsCount = service.GetAll().Count();

            // Assert
            Assert.AreEqual(2, teamsCount);
        }

        [TestMethod]
        public void AddTeamTest()
        {
            // Arange
            Team team = new Team();
            team.Name = "Team1";

            IEnumerable<Team> teams = new List<Team>();

            unitOfWork.Setup(uow =>
                uow.Teams.All()).Returns(teams.AsQueryable());

            var service = new TeamsService(unitOfWork.Object);
            // Act
            service.Add(team);

            // Assert
            Assert.AreEqual(1, teams.Count());
        }
    }
}
